package base016

import (
	"fmt"
	"math/rand"
	"strconv"
	"time"
)

func BaseTime()  {
	now := time.Now()
	fmt.Println("时间戳(秒)：", now.Unix())
	fmt.Println("时间戳(纳秒):", now.UnixNano())
	fmt.Println("时间戳(毫秒)：", now.UnixNano()/1e6)
	fmt.Println("时间戳(纳秒转毫秒)：", now.UnixNano()/1e9)

	//时间格式化
	fmt.Println(now.Format("02/1/2006 15:04"))
	fmt.Println(now.Format("2006/1/02 15:04"))
	//显示时分秒
	fmt.Println(now.Hour(),now.Minute(),now.Second())

	//条件判断
	if now.Unix() > 200000 {
		fmt.Println("搞笑1")
	}else if now.Unix() > 300000 {
		fmt.Println("搞笑2")
	}else {
		fmt.Println("搞笑3")
	}

	//循环
	forFun()
}

func forFun(){
	//switch 循环
	var num = rand.Intn(10)
	switch num {
	case 1,2,3,4,5:
		fmt.Println("switch1")
	case 6:
		fmt.Println("switch2")
	case 7,8,9:
		fmt.Println("switch3")
	default:
		fmt.Println("switch4")
	}
	switch {
	case num < 5:
		fmt.Println("switch if 1")
	case num == 5:
		fmt.Println("switch if 2")
	case num < 8:
		fmt.Println("switch if 3")
	default:
		fmt.Println("switch if 4")
	}

	//for 代替while
	for i := 0; i <= 4; i++ {
		if i == 2 {
			continue
		}else if i == 4 {
			break
		}

		str := strconv.Itoa(i)
		fmt.Println("for",str)
	}

	var n = 2
	for n > 0 {
		str := strconv.Itoa(n)
		fmt.Println("while",str)
		n --
	}

	//遍历数组
	var mm = []int{66, 20, 30, 40}
	for key, value := range mm {
		fmt.Printf("key:%d  value:%d\n", key, value)
	}

	//可以指定跳回之前的地方
	i := 8
FIRST: //这里大小写无所谓
	fmt.Println(i)
	i --
	if i == 4 {
		return
	}
	goto FIRST
}

